package com.my.main;

import com.my.Config.RootConfig;
import com.my.bean.User;
import com.my.utils.ApplicationContextutils;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class jdbcTemplateText {


      @Test
        public void text(){

        ApplicationContext applicationContext = ApplicationContextutils.getApplicationContext();

        JdbcTemplate jdbcTemplate = applicationContext.getBean(JdbcTemplate.class);


        List<User> query = jdbcTemplate.query("select * from user where id=1", new RowMapper<User>() {
          @Override
          public User mapRow(ResultSet resultSet, int i) throws SQLException {
            String username = resultSet.getString("username");
            String password = resultSet.getString("password");

            System.out.println(resultSet);
            User user = new User();
            user.setUsername(username).setPassword(password);
            return user;
          }
        });
        for (User user : query) {
          System.out.println(user);
        }
      }


}
